//
//  YIem_FindDetail_Time_TableViewCell.m
//  B段_开眼
//
//  Created by YIem on 16/4/25.
//  Copyright © 2016年 Howie. All rights reserved.
//

#import "YIem_FindDetail_Time_TableViewCell.h"
#define kHeight [UIScreen mainScreen].bounds.size.height
@interface YIem_FindDetail_Time_TableViewCell ()

@property (nonatomic, strong) UIImageView *imageBack;
@property (nonatomic, strong) UILabel *labelTitle;
@property (nonatomic, strong) UILabel *labelTime;
@end
@implementation YIem_FindDetail_Time_TableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.imageBack = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageBack];
        self.labelTitle = [[UILabel alloc] init];
        self.labelTitle.font = [UIFont systemFontOfSize:20 weight:2];
        self.labelTitle.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.labelTitle];

        
        self.labelTime = [[UILabel alloc] init];
        self.labelTime.font = [UIFont systemFontOfSize:16];
        self.labelTime.textColor = [UIColor whiteColor];
        [self.contentView addSubview:self.labelTime];
        
        
        
    }
    return self;
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    
//    self.imageBack.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
    [self.imageBack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(self.frame.size.width, self.frame.size.height));
    }];
    
    
//    self.labelTitle.frame = CGRectMake(0, 0, 200, 40);
    [self.labelTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.imageBack);
        
//        make.centerY.equalTo(self.imageBack);
//        make.centerY.equalTo(self.imageBack);
//        make.size.mas_equalTo(CGSizeMake(300, 40));
        
    }];
//    self.labelTime.frame = CGRectMake(0, 50, 100, 30);
    [self.labelTime mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.labelTitle.mas_top).height.offset(10);
        make.centerX.equalTo(self.imageBack);
        make.centerY.mas_equalTo(self.labelTitle.mas_centerY);
    }];
}
- (void)setModel:(EveryCellModel *)model
{
    _model = model;
    [self.imageBack sd_setImageWithURL:[NSURL URLWithString:model.feed]];
//    self.labelTitle.text = model.title;
    
    
    NSString *timeStr = model.date;
    long long int date1 = (long long int)[timeStr intValue];
    
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:date1];
    NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
    [dateForm setDateFormat:@"MM:dd"];
    
    NSString *dateS = [dateForm stringFromDate:date];
    self.labelTime.text = [NSString stringWithFormat:@"#%@ / %@",model.category, dateS];
}


- (CGFloat)cellOffset {
    
    CGRect centerToWindow = [self convertRect:self.bounds toView:self.window];
    CGFloat centerY = CGRectGetMidY(centerToWindow);
    CGPoint windowCenter = self.superview.center;
    
    CGFloat cellOffsetY = centerY - windowCenter.y;
    
    CGFloat offsetDig =  cellOffsetY / self.superview.frame.size.height *2;
    CGFloat offset =  -offsetDig * (kHeight/1.7 - 250)/2;
    
    CGAffineTransform transY = CGAffineTransformMakeTranslation(0,offset);
    
    //    self.titleLabel.transform = transY;
    //    self.littleLabel.transform = transY;
    
    self.imageBack.transform = transY;
    
    return offset;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
